package com.lanyou.esb.cook.proxy.entity;

import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lanyou.esb.cook.proxy.common.Constants;
import com.lanyou.esb.cook.proxy.meta.EnableType;

/**
 * 接口报警信息表
 * 
 * @author Davey.wu
 */
public class IfAlarm {
	/** 接口报警表id **/
	private String id;//
	/** 接口id **/
	private String ifId;//
	/** 接口编码 **/
	private String ifCode;//
	/** 接口版本 **/
	private String ifVersion;//
	/** 接口类型 **/
	private String ifType;//
	/** 接口名字 **/
	private String ifName;//
	/** 系统 **/
	private String systemId;//
	/** 系统编号 **/
	private String systemCode;//
	/** 报警类型 **/
	private String alarmType;//
	/** 报警等级 **/
	private String alarmLevel;//
	/** 进去esb时间 **/
	private Date inEsbDate;//
	/** 离开essb时间 **/
	private Date outEsbDate;//
	/** 平台发送请求时间 **/
	private Date platReqDate;//
	/** 平台接收请求时间 **/
	private Date platResDate;//
	/** 流量 **/
	private int flow;//
	/** 响应时长 **/
	private float answerTime;//
	/** 请求阀值 **/
	private int fowThreshold;//
	/** 发生时间 **/
	private Date errorDate;//
	/** 错误接收者 **/
	private String errorReceiver;//
	/** 工单号 **/
	private String assignWorkCode;//
	/** 是否可用 **/
	private String isEnable;
	/****/
	private String creator;
	/****/
	private String modifier;
	/****/
	private Date createDate;
	/****/
	private Date lastUpdatedDate;
	/** 重复次数 **/
	private int repeat = 1;
	/** http响应码 **/
	private String resCode;
	/** 请求来源 **/
	private String reqIp;
	/** 请求方式 **/
	private String reqMethod;
	/** 请求URL **/
	private String reqUrl;
	/** 请求报文 **/
	private String reqMess;
	/** 告警点峰值 **/
	private float peakValue;
	/** 邮件接收人 **/
	private String emailReceiver;
	/** 关联工单 **/
	private IfAlarmWorkOrder order;
	/** 是否是重复告警 **/
	private boolean isRepeat;

	private static int MAX_REQ_MESS_LENGHT = 3000;

	public IfAlarm() {
		this.id = UUID.randomUUID().toString().replaceAll("-", "");
		Date now = new Date();
		this.createDate = now;
		this.lastUpdatedDate = now;
		this.isEnable = EnableType.ENABLE.ValueCode;
	}

	public IfAlarm setCallSystemCode(String callSystemCode) {
		this.callSystemCode = callSystemCode;
		return this;
	}

	private String callSystemCode;

	public String getId() {
		return id;
	}

	public IfAlarm setId(String id) {
		this.id = id;
		return this;
	}

	public String getIfId() {
		return ifId;
	}

	public IfAlarm setIfId(String ifId) {
		this.ifId = ifId;
		return this;
	}

	public String getIfType() {
		return ifType;
	}

	public IfAlarm setIfType(String ifType) {
		this.ifType = ifType;
		return this;
	}

	public String getIfName() {
		return ifName;
	}

	public IfAlarm setIfName(String ifName) {
		this.ifName = ifName;
		return this;
	}

	public String getSystemId() {
		return systemId;
	}

	public IfAlarm setSystemId(String systemId) {
		this.systemId = systemId;
		return this;
	}

	public String getSystemCode() {
		return systemCode;
	}

	public IfAlarm setSystemCode(String systemCode) {
		this.systemCode = systemCode;
		return this;
	}

	public String getAlarmType() {
		return alarmType;
	}

	public IfAlarm setAlarmType(String alarmType) {
		this.alarmType = alarmType;
		return this;
	}

	public String getAlarmLevel() {
		return alarmLevel;
	}

	public IfAlarm setAlarmLevel(String alarmLevel) {
		this.alarmLevel = alarmLevel;
		return this;
	}

	public Date getInEsbDate() {
		return inEsbDate;
	}

	public IfAlarm setInEsbDate(Date inEsbDate) {
		this.inEsbDate = inEsbDate;
		return this;
	}

	public Date getOutEsbDate() {
		return outEsbDate;
	}

	public IfAlarm setOutEsbDate(Date outEsbDate) {
		this.outEsbDate = outEsbDate;
		return this;
	}

	public Date getPlatReqDate() {
		return platReqDate;
	}

	public IfAlarm setPlatReqDate(Date platReqDate) {
		this.platReqDate = platReqDate;
		return this;
	}

	public Date getPlatResDate() {
		return platResDate;
	}

	public IfAlarm setPlatResDate(Date platResDate) {
		this.platResDate = platResDate;
		return this;
	}

	public float getAnswerTime() {
		return answerTime;
	}

	public IfAlarm setAnswerTime(float answerTime) {
		this.answerTime = answerTime;
		return this;
	}

	public Date getErrorDate() {
		if (errorDate == null) {
			errorDate = this.getCreateDate();
		}
		return errorDate;
	}

	public IfAlarm setErrorDate(Date errorDate) {
		this.errorDate = errorDate;
		return this;
	}

	public String getErrorReceiver() {
		return errorReceiver;
	}

	public IfAlarm setErrorReceiver(String errorReceiver) {
		this.errorReceiver = errorReceiver;
		return this;
	}

	public String getAssignWorkCode() {
		return assignWorkCode;
	}

	public IfAlarm setAssignWorkCode(String assignWorkCode) {
		this.assignWorkCode = assignWorkCode;
		return this;
	}

	public String getCreator() {
		return StringUtils.isEmpty(creator) ? Constants.DEFAULT_USER : creator;
	}

	public IfAlarm setCreator(String creator) {
		this.creator = creator;
		return this;
	}

	public String getModifier() {
		return StringUtils.isEmpty(modifier) ? Constants.DEFAULT_USER
				: modifier;
	}

	public IfAlarm setModifier(String modifier) {
		this.modifier = modifier;
		return this;
	}

	public int getFlow() {
		return flow;
	}

	public IfAlarm setFlow(int flow) {
		this.flow = flow;
		return this;
	}

	public int getFowThreshold() {
		return fowThreshold;
	}

	public IfAlarm setFowThreshold(int fowThreshold) {
		this.fowThreshold = fowThreshold;
		return this;
	}

	public String getIsEnable() {
		return isEnable;
	}

	public IfAlarm setIsEnable(String isEnable) {
		this.isEnable = isEnable;
		return this;
	}

	public Date getLastUpdatedDate() {
		return lastUpdatedDate;
	}

	public IfAlarm setLastUpdatedDate(Date lastUpdatedDate) {
		this.lastUpdatedDate = lastUpdatedDate;
		return this;
	}

	public Date getCreateDate() {
		return createDate == null ? new Date() : createDate;
	}

	public IfAlarm setCreateDate(Date createDate) {
		this.createDate = createDate;
		return this;
	}

	public String getIfCode() {
		return ifCode;
	}

	public IfAlarm setIfCode(String ifCode) {
		this.ifCode = ifCode;
		return this;
	}

	public String getCallSystemCode() {
		return callSystemCode;
	}

	public String getIfVersion() {
		return ifVersion;
	}

	public IfAlarm setIfVersion(String ifVersion) {
		this.ifVersion = ifVersion;
		return this;
	}

	public int getRepeat() {
		return repeat;
	}

	public IfAlarm setRepeat(int repeat) {
		this.repeat = repeat;
		return this;
	}

	public String getResCode() {
		return resCode;
	}

	public IfAlarm setResCode(String resCode) {
		this.resCode = resCode;
		return this;
	}

	public String getReqIp() {
		return reqIp;
	}

	public IfAlarm setReqIp(String reqIp) {
		this.reqIp = reqIp;
		return this;
	}

	public String getReqMethod() {
		return reqMethod;
	}

	public IfAlarm setReqMethod(String reqMethod) {
		this.reqMethod = reqMethod;
		return this;
	}

	public String getReqUrl() {
		return reqUrl;
	}

	public IfAlarm setReqUrl(String reqUrl) {
		this.reqUrl = reqUrl;
		return this;
	}

	/**
	 * 最大长度有限制
	 * 
	 * @return
	 */
	public String getReqMess() {
		if (reqMess != null && reqMess.length() > MAX_REQ_MESS_LENGHT) {
			reqMess = reqMess.substring(0, MAX_REQ_MESS_LENGHT);
		}
		return reqMess;
	}

	public IfAlarm setReqMess(String reqMess) {
		this.reqMess = reqMess;
		return this;
	}

	public float getPeakValue() {
		return peakValue;
	}

	public IfAlarm setPeakValue(float peakValue) {
		this.peakValue = peakValue;
		return this;
	}

	public void incRepeat() {
		this.repeat++;
	}

	public String getEmailReceiver() {
		return emailReceiver;
	}

	public IfAlarm setEmailReceiver(String emailReceiver) {
		this.emailReceiver = emailReceiver;
		return this;
	}

	public IfAlarmWorkOrder getOrder() {
		return order;
	}

	public void setOrder(IfAlarmWorkOrder order) {
		this.order = order;
	}

	@JsonIgnore
	public boolean isRepeat() {
		return isRepeat;
	}

	public void setRepeat(boolean isRepeat) {
		this.isRepeat = isRepeat;
	}
}